package student.aistar.util;

import java.sql.*;

public class JdbcUtil {
    public static Connection getConnection() throws SQLException {
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/m503?useSSL=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai", "root", "Abc1234!");
        return connection;
    }
    public static void close(Connection connection, Statement statement){
        if(null!=statement){
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(null!=connection){
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    public static void close(Connection connection, Statement statement, ResultSet resultSet) throws SQLException {
        resultSet.close();
        statement.close();
        if(null != connection){
            resultSet.close();
        }
    }
}
